/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import classes.Seat;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Sarah
 */
@Stateless
public class PcroomlistFacade extends AbstractFacade<Pcroomlist> {

    @PersistenceContext(unitName = "IServer-ejbPU")
    private EntityManager em;
    Pcroomlist room;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PcroomlistFacade() {
        super(Pcroomlist.class);
    }

    public void addPcroom(String name, double la, double lo, String add, String tel, ArrayList<Seat> seats) {
        room = new Pcroomlist();
        room.setName(name);
        room.setLatitude(la);
        room.setLongitude(lo);
        room.setAddress(add);
        room.setTel(tel);
        room.setSeats(seats);

        System.out.println(name);
        System.out.println(add);
        System.out.println(tel);

        create(room);
    }

    public void addPcroom(String name, double la, double lo, String add, String tel) {
        room = new Pcroomlist();
        room.setName(name);
        room.setLatitude(la);
        room.setLongitude(lo);
        room.setAddress(add);
        room.setTel(tel);

        System.out.println(name);
        System.out.println(add);
        System.out.println(tel);

        create(room);
    }

    public void reserve(String uid, long pid, ArrayList<Integer> seat) {
        for (int i = 0; i < seat.size(); i++) {
            for (Seat s : room.getSeats()) {
                if (s.getNum() == seat.get(i)) {
                    s.getInfo().setIsAvailable(Boolean.FALSE);
                    s.getInfo().setuId(uid);
                    break;
                }
            }
        }
    }
}
